package Controller.Actions.Modify;

import Controller.*;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import Model.Beans.Results.*;
import Model.Beans.*;
import Model.QBE.*;

public class ModifyProfessorAction implements Action {
    
    private String name; 
    
    public ModifyProfessorAction() 
    {
        this.name = "ModifyProfessor";
    }
    
    public String getName()
    {
        return name;
    }
   
    public void perform(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
        
        response.setContentType("text/xml");
        response.setHeader("Cache-Control", "no-cache");
        ProfessorModel pmodel = new ProfessorModel();
        String id = request.getParameter("id");
        String name = request.getParameter("name");
        String lastname1 = request.getParameter("firstLastName");
        String lastname2 = request.getParameter("secondLastName");
        
        Person professor = new Person(Integer.parseInt(id), name, lastname1, lastname2);
        if(pmodel.modify(professor) != 0)
        {
            response.getWriter().write("<message> The professor " + professor.toString() +  " has been successfully modified </message>");
        }
        else
        {
            response.getWriter().write("<message>The professor doesn't exists </message>");
        }
       
    }
}
